import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import {resolve} from "path";

import { webConfig } from "./config.js";

export default defineConfig({
    plugins:[
        vue(),
        // 配置插件
        AutoImport({
            imports:["vue","vue-router"],
            resolvers: [ElementPlusResolver()]
        }),
        Components({
            resolvers: [ElementPlusResolver()]
        })
    ],
    resolve:{
        // 配置路径别名
        alias:{
            "@":resolve(__dirname,"./src")
        }
    },
    server:{
        // 代理服务器
        proxy:{
            "/Qilin":{
                target:webConfig.proxyUrl,
                changeOrigin:true, //允许跨域
                ws:true, //允许websocket代理
                rewrite:(path)=>path.replace(/^\/Qilin/,"")
            },
            "/Mock":{
                target:webConfig.mockUrl,
                changeOrigin:true, //允许跨域
                ws:true, //允许websocket代理
                rewrite:(path)=>path.replace(/^\/Mock/,"")
            }
        }
    },
    css:{
        devSourcemap:true, //开发模式下开启css样式sourceMap
        preprocessorOptions:{
            scss:{
                api:"modern-compiler",
                additionalData:"@use '@/assets/scss/common.scss' as *;@use '@/assets/scss/base.scss' as *;"
            }
        }
    },
    build:{
        minify:"esbuild",
        // minify:"terser",
        chunkSizeWarningLimit:1000, //单个模块文件大小限制1000kb
        terserOptions:{
            compress:{ //清除代码中的console和debugger
                drop_console:true,
                drop_debugger:true
            }
        },
        rollupOptions:{
            output:{
                manualChunks(id){
                    if(id.includes("node_modules")){
                        return id.toString().split("node_modules/")[1].split("/")[0].toString();
                    }
                }
            }
        }
    }
})

